(function(window) {
	var moveObj = staticObj.extend({
		// 是否可以接收控制
		canControl: null,
		// 按键地图
		keyMap: null,
		// 方向
		direction: null,
		// 速度
		speed: null,
		// 地图
		map: null,

		ctor: function(opts) {
			this._super(opts);

			// opts
			this.direction = dino.DEFAULT.direction; // 默认面朝下
			this.speed = opts.speed || dino.DEFAULT.speed;
			this.map = opts.map;
			this.canControl = !! opts.canControl;


			this.keyMap = opts.keyMap;

			this.scheduleUpdate();

		},
		onEnter: function() {
			this._super();
			this.changeStatus("create");
		},
		// 移动(尝试去移动,但是不一定可以移动)
		move: function(dt) {
			var _dist = parseInt(this.speed * dt);
			console.log('_dist', _dist);
			var dist = cc.p(0, 0);
			switch(this.direction) {
			case "up":
				dist.y += _dist;
				break;
			case "right":
				dist.x += _dist;
				break;
			case "down":
				dist.y -= _dist;
				break;
			case "left":
				dist.x -= _dist;
				break;
			}
			var currPosi = this.getPosition();
			var nextPosi = cc.p(currPosi.x + dist.x, currPosi.y + dist.y);

			this.trigger("beforeMove", {
				currPosi: currPosi,
				nextPosi: nextPosi
			});

		},
		// 转向
		changeDire: function(dire) {
			var currDire = this.direction;
			var nextDire = dire;
			var rst = false;
			if(currDire == nextDire) {
				console.info("no direction change!!");
				rst = false;
			} else {
				var lastDire = currDire;
				this.direction = nextDire;
				this.trigger("afterDireChanged", {
					lastDire: lastDire,
					currDire: this.direction
				});
				rst = true;
			}
			return rst;
		},
		update: function(dt) {
			if(this.canControl) {
				var opts = {
					dt: dt
				};
				triggerKeyMap.call(this, this.keyMap, dino.keys, opts);
			}
		}

	});

	function triggerKeyMap(keyMap, keys, opts) {
		if(keyMap) {
			for(var i in keyMap) {
				var kmi = keyMap[i];
				keys[i] && kmi.call(this, i, opts);
			}
		}
	}



	window.moveObj = moveObj;
})(window);